package com.qidian.mes.sys.service.impl;

import com.qidian.mes.pojo.Dict;
import com.qidian.mes.pojo.User;
import com.qidian.mes.sys.mapper.UserMapper;
import com.qidian.mes.sys.service.UserService;
import com.qidian.mes.util.dot.PagerDTO;
import com.qidian.mes.util.pojo.QdResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author 戴着假发的程序员
 * @Company 起点编程
 * @Description
 * @Time 2024/4/11 11:32
 */
@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Value("${server.port}")
    private int port; // 获取当前服务的端口
    @Override
    public QdResult queryByPage(User user, Integer page, Integer limit) {
        PagerDTO<User> pagerDTO = new PagerDTO<>();
        pagerDTO.setPage(page);
        pagerDTO.setLimit(limit);
        pagerDTO.setTotal(userMapper.selectCount(user));
        pagerDTO.setData(userMapper.selectUserByPage(user,(page - 1) * limit,limit));
        // 响应数据的时候，将端口信息放在msg中
        return QdResult.success("实际服务的端口：" + port,pagerDTO);
    }

    @Override
    public QdResult<Integer> saveUsers(List<User> users) {
        return QdResult.success(userMapper.insertUsers(users));
    }

    @Override
    public QdResult saveUser(User user) {
        return QdResult.isSuccess(userMapper.insertUser(user));
    }


}
